package com.luoc.base.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.luoc.base.exception.LuocException;
import com.luoc.base.model.Result;
import com.luoc.base.entity.User;
import com.luoc.base.service.UserService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: luoc
 * @Date: 2019/7/4 9:16
 */

@Slf4j
@RequestMapping("user")
@RestController
@Api(value = "用户操作", tags = {"用户模块"})
public class UserController {

    @Autowired
    UserService userService;

    @PostMapping("login")
    public Result login(User dto) {
        try {
            if (dto == null) {
                throw new LuocException("参数为空");
            }
            return Result.ok(userService.getOne(new QueryWrapper<User>().eq("name", dto.getName()), true));
        } catch (LuocException e) {
            log.error(e.getMessage());
            return Result.error(e.getMessage());
        } catch (Exception e) {
            log.error("语法异常", e);
            return Result.error("error");
        }

    }
}
